
#if !SILVERLIGHT
using QdbUnit;
using Qdb.CS;
using Qdb.CS.Config;
using Qdb.Ext;
using Qdb.IO;
using Qdb.Internal;

namespace Qdb.Tests.Common.CS
{
	public abstract class EmbeddedAndNetworkingClientTestCaseBase : ITestLifeCycle
	{
		private static readonly string Username = "qdb";

		private static readonly string Password = "qdb";

		private IExtObjectServer _server;

		private IExtObjectContainer _networkingClient;

		private ObjectContainerSession _embeddedClient;

		/// <exception cref="System.Exception"></exception>
		public virtual void SetUp()
		{
			IServerConfiguration serverConfiguration = QdbClientServer.NewServerConfiguration
				();
			serverConfiguration.File.Storage = new MemoryStorage();
			_server = QdbClientServer.OpenServer(serverConfiguration, string.Empty, QdbClientServer
				.ArbitraryPort).Ext();
			_server.GrantAccess(Username, Password);
			_networkingClient = QdbClientServer.OpenClient("localhost", _server.Port(), Username
				, Password).Ext();
			this._embeddedClient = ((ObjectContainerSession)_server.OpenClient().Ext());
		}

		/// <exception cref="System.Exception"></exception>
		public virtual void TearDown()
		{
			EmbeddedClient().Close();
			NetworkingClient().Close();
			_server.Close();
		}

		protected virtual IExtObjectContainer NetworkingClient()
		{
			return _networkingClient;
		}

		protected virtual ObjectContainerSession EmbeddedClient()
		{
			return _embeddedClient;
		}

		protected virtual IExtObjectContainer ServerObjectContainer()
		{
			return _server.ObjectContainer().Ext();
		}
	}
}
#endif // !SILVERLIGHT
